<template>
    <div>

        <el-form :model="PassWordForm" :rules="UpdateFormRules" ref="UpdateFormRef">
            <h2 class="Regi-title">重置密码</h2>
            <!-- 密码 -->
            <el-form-item prop="password">
                <el-input v-model="PassWordForm.password" placeholder="请输入新密码" show-password></el-input>
            </el-form-item>
            <!-- 确认密码 -->
            <el-form-item prop="password1">
                <el-input v-model="PassWordForm.password1" placeholder="请输入确认新密码" show-password></el-input>
            </el-form-item>
            <!-- 输入验证码 -->
            <el-form-item>
                <el-input v-model="PassWordForm.code" placeholder="请输入邮箱验证码"></el-input>
            </el-form-item>
            <el-form-item class="El-Button-Submit">
                <el-button type="primary" @click="SubmitUpdate">提交</el-button>
                <el-button type="info" @click="ResetUpdate">重置</el-button>

            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { update_pwd_put } from '../axios_api/api'
export default {
    props: {
        UpdateForm: Object
    },
    data() {
        return {
            PassWordForm: {
                password: '',	// 密码
                password1: '',	// 确认密码
                code: '', // 验证码
            },
            // 这是表单的验证规则对象
            UpdateFormRules: {
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { pattern: /^[a-zA-Z]([a-zA-Z0-9]){5,16}$/, message: '密码以字母开头，且长度在 6 到 16 个字符' },
                ],
                // 验证两次密码是否一致
                password1: [
                    { required: true, message: '请输入确认密码', trigger: 'blur' },
                    { pattern: /^[a-zA-Z]([a-zA-Z0-9]){5,16}$/, message: '两次密码不一致' },
                ],
            },
            pswd1: false,
            Power: [],
        }
    },
    mounted() {
        console.log(this.code)
    },
    methods: {
        // 提交修改
        SubmitUpdate() {
            this.$refs.UpdateFormRef.validate(valid => {
                if (!valid) return;
                // 发起注册提交请求
                let data = { UpdateForm: this.UpdateForm, PassWordForm: this.PassWordForm }
                update_pwd_put(data).then(resp => {
                    if (resp.code === 200) {
                        this.$message.success(resp.message)
                        this.$router.push('/login')
                    } else {
                        this.$message.error(resp.message)
                    }
                })
            })
        },
        // 重置输入数据
        ResetUpdate() {
            this.$refs.UpdateFormRef.resetFields();
        },
    },
}
</script>

<style>
</style>